import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Register from '../views/Register.vue'
import NotFound from '../views/NotFound.vue'
import ResetPassword from '../views/Resetpassword.vue'
import ImageProcessing from '../views/image_analyse.vue' // 导入图像处理页面组件

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: '/login' // 默认重定向到登录页
    },
    {
        path: '/login',
        name: 'LoginPage',
        component: Login
    },
    {
        path: '/register',
        name: 'RegisterPage',
        component: Register
    },
    {
        path: '/reset-password/',
        name: 'ResetPasswordPage',
        component: ResetPassword
    },
    {
        path: '/not-found',
        name: 'NotFoundPage',
        component: NotFound
    },
    {
        path: '/image-processing', // 添加图像处理页面的路由
        name: 'ImageProcessingPage',
        component: ImageProcessing,
        meta: { requiresAuth: true } // 如果需要登录才能访问，可以添加这个元字段
    },
    {
        path: '*', // 匹配所有未定义的路由
        redirect: '/not-found'
    }
]

const router = new VueRouter({
    mode: 'history',
    routes
})

// 如果需要登录验证，可以添加全局路由守卫
router.beforeEach((to, from, next) => {
    if (to.matched.some(record => record.meta.requiresAuth)) {
        // 检查用户是否已登录
        const isAuthenticated = localStorage.getItem('token') // 或者其他验证方式
        if (!isAuthenticated) {
            next('/login')
        } else {
            next()
        }
    } else {
        next()
    }
})

export default router